package com.example.qxfw.csnl.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.WaterloggingYzdisppara;
import com.example.qxfw.common.entity.zy.WaterLoggingLevelSetting;
import com.example.qxfw.csnl.entity.ColorSelectionResponse;
import com.example.qxfw.csnl.service.YzszService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "城市内涝-因子设置")
@RestController
@CrossOrigin
@RequestMapping("/FactorSettingsController")
public class FactorSettingsController {

    @Autowired
    private YzszService yzszService;

    @ApiOperation("城市内涝--因子设置-获取颜色")
    @GetMapping("/getColor")
    public ColorSelectionResponse getColor(int color){
        return new ColorSelectionResponse(color);
    }

    @ApiOperation("城市内涝-因子设置-添加")
    @PostMapping("/insertOfWaterLoggingLevelSetting")
    public SysResult insertOfWaterLoggingLevelSetting(@RequestBody WaterLoggingLevelSetting waterLoggingLevelSetting){
        WaterLoggingLevelSetting result = yzszService.insertOfWaterLoggingLevelSetting(waterLoggingLevelSetting);
        if (result != null) {
            return SysResult.success(result);
        }else {
            return SysResult.fail("添加数据失败！！！");
        }
    }
    @ApiOperation("城市内涝-因子设置-删除")
    @DeleteMapping("/deleteById")
    public SysResult deleteById(int id){
        int result = yzszService.deleteById(id);
        return SysResult.success(result);
    }

    @ApiOperation("城市内涝-因子设置-修改")
    @PutMapping("/updateById")
    public SysResult updateById(@RequestBody WaterLoggingLevelSetting waterLoggingLevelSetting){
        WaterLoggingLevelSetting result = yzszService.updateById(waterLoggingLevelSetting);
        if (result != null) {
            return SysResult.success(result);
        }else {
            return SysResult.fail("更新数据失败！！！");
        }
    }

    @ApiOperation("城市内涝-因子设置-查询")
    @GetMapping("/getAllWaterLoggingLevelSetting")
    public SysResult getAllWaterLoggingLevelSetting(){
        List<WaterloggingYzdisppara> allWaterLoggingLevelSetting = yzszService.getAllWaterLoggingLevelSetting();
        return SysResult.success(allWaterLoggingLevelSetting);
    }

}
